/**
 * @param {number[]} nums
 * @return {number[]}
 */
var findDisappearedNumbers = function (nums) {
    let n = nums.length;
    let res = 0;

    // 先和新补的索引异或一下
    res ^= n;

    // 和其它的元素、索引做异或
    for (let i = 0; i < n; i++) {
        res ^= i ^ nums[i];
    }
    return res;
};


/**
 * @param {number[]} nums
 * @return {number}
 */
var missingNumber = function (nums) {
    let n = nums.length;
    let res = 0;
    // 新补的索引
    res += n - 0;

    // 剩下索引和元素的差加起来
    for (let i = 0; i < n; i++) {
        res += i - nums[i];
    }
    return res;
};



/**
 * @param {number[]} nums
 * @return {number[]}
 */
var findDisappearedNumbers = function (nums) {
    for (let i = 0; i < nums.length; i++) {
        let newIndex = Math.abs(nums[i]) - 1;
        if (nums[newIndex] > 0) {
            nums[newIndex] *= -1;
        }
    }

    let result = [];
    for (let i = 1; i <= nums.length; i++) {
        if (nums[i - 1] > 0) {
            result.push(i);
        }
    }
    return result;
};


